import { GetHiddenMenuList, getUserMenuList } from "@/apis/menu";
import { ContentType } from "@/store";

/** 获取菜单，和权限按钮 */
export const useGetMenu = (globalDispatch: ContentType["globalDispatch"]) => {
  const getMenuFn = async () => {
    var [data, menuPower, hideMenu] = await Promise.all([getUserMenuList(1), getUserMenuList(2), GetHiddenMenuList()]);

    const menuData = [...data, ...hideMenu];

    globalDispatch({
      type: "MENU_LIST",
      data: menuData || [],
    });

    globalDispatch({
      type: "powerButtonList",
      data: (menuPower || []).map((v: any) => v.cdqx),
    });
  };

  /** 获取登录用户信息 */
  const initUserInfo = async () => {
    // const data = await getUserInfo();

    // globalDispatch({
    //   type: "userInfoData",
    //   data,
    // });
  };

  return { getMenuFn, initUserInfo };
};
